UIImage - should be loaded with [UIImage imageNamed:@""] or not ?

Posted by sagar on Stack Overflow See other posts from Stack Overflow or by sagar
Published on 2010-04-10T06:52:28Z Indexed on 2010/04/10 7:13 UTC
Read the original article Hit count: 299

Filed under:
|
|
|
|

Hello ! every one.

  • I am having number of images with in my application. ( images more than 50 - approximately & it can extend according to client's need )
  • Each image are very large round about - 1024 x 768 & 150 dpi
  • Now, I have to add all this images in a scroll view & display it.

Ok, My question is as follows.

According to me there are two options of loading large images

  1. imageNamed:@""
  2. load asynchronously when viewDidLoad Called.

Which is more preferable ?


imgModel.image=[UIImage imageNamed:[dMain valueForKey:@"imgVal"]];

or like this.

    NSURL *ur=[[NSURL alloc] initFileURLWithPath:[[NSBundle mainBundle] pathForResource:lblModelName.text ofType:@"png"] isDirectory:NO];

    NSURLRequest *req=[NSURLRequest requestWithURL:ur cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:40];
    [ur release];
    NSURLConnection *con=[[NSURLConnection alloc] initWithRequest:req delegate:self];
    if(con){
        myWebData=[[NSMutableData data] retain];
    } else {
    }

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [myWebData setLength: 0];
}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [myWebData appendData:data];
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    [connection release];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSLog(@"ImageView Ref From - %@",imgV);
    // my image view & set image  
    imgV.image=[UIImage imageWithData:myWebData];
    [connection release]; connection=nil;
}

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c